#include<vector>
#include<iostream>

namespace bite
{
	template<class T>
	class stack
	{
	public:
		stack() {}
		void push(const T& x)
		{
			_c.push_back(x);
		}
		void pop()
		{
			_c.pop_back();
		}
		T& top()
		{
			return _c.back();
		}
		const T& top()const
		{
			return _c.back();
		}
		size_t size()const
		{
			return _c.size();
		}
		bool empty()const
		{
			return _c.empty();
		}
	private:
		std::vector<T> _c;
	};
}
#include<list>
namespace bit
{
	template<class T>
	class queue
	{
	public:
		queue() {}
		void push(const T& x)
		{
			_c.push_back(x);
		}
		void pop()
		{
			_c.pop_front();
		}
		T& back()
		{
			return _c.back();
		}
		const T& back()const
		{
			return _c.front();
		}
		T& front()
		{
			return _c.front();
		}
		const T& front()const
		{
			return _c.front();
		}
		size_t size()const
		{
			return _c.size();
		}
	private:
		std::list<T> _c;
	};
}

#include<queue>
#include<functional>
#include<iostream>

//void TestPriorityQueue()
//{
//	std::vector<int> v{ 3,2,7,21,0,8,4,6 };
//	std::priority_queue<int> q1;
//	for (auto& e : v)
//		q1.push(e);
//	
//	cout << q1.top() << endl;
//
//	std::priority_queue<int, vector<int>, greater<int>>q2(v.begin(), v.end());
//	cout << q2.top() << endl;
//}

using namespace std;
class Solution {
public:
	vector<vector<int>> levelOrder(TreeNode* root) {
		queue<TreeNode*> que;
		vector<vector<int>> res;
		if (root != nullptr)
			que.push(root);
		while (!que.empty())
		{
			vector<int> tmp;
			for (int i = que.size(); i > 0; i--)
			{
				TreeNode* p = que.front;
				que.pop();
				tmp.push_back(p->val);
				if (p->left != nullptr)que.push(p->left);
				if (p->right != nullptr)que.push(p->righr);
			}
			res.push_back(tmp);
		}
		return res;
	}
};